#include "AckleyFunction.hpp"
#include <cmath>

void AckleyFunction::operator()(Specimen &argument)
{
	double n_ = (double)1/_dims;
  double sum1 = 0.0;
  double sum2 = 0.0;

  for ( unsigned i = 0; i < _dims; i++ )
    {
      sum1 += pow(argument[i],2);
      sum2 += cos(2*PI*argument[i]);
    }
  
  double fx = -20.0*exp(-0.2*sqrt(n_)*sum1) - exp(n_*sum2);
  
  argument.setFitness(fx);
}
/* zostawiam tutaj kod oryginału
double ackley(vector<double> x)
{
	int i, n = x.size();
	double n_ = (double)1/n;
	double sum1 = 0.0;
	double sum2 = 0.0;
	
	for ( i = 0; i < n; i++ )
	{
		sum1 += pow(x[i],2);
		sum2 += cos(2*PI*x[i]);
	}

	double fx = -20.0*exp(-0.2*sqrt(n_)*sum1) - exp(n_*sum2);
	return fx;
	}
*/
